<!-- saved from url=(0014)about:internet -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>AuxFunctions.as</title>
<link rel="stylesheet" type="text/css" href="../../../SourceStyles.css"/>
</head>

<body><pre><span class="ActionScriptpackage">package</span> <span class="ActionScriptDefault_Text">caurina</span>.<span class="ActionScriptDefault_Text">transitions</span> <span class="ActionScriptBracket/Brace">{</span>

    <span class="ActionScriptASDoc">/**
     * Generic, auxiliary functions
     *
     * @author        Zeh Fernando
     * @version        1.0.0
     * @private
     */</span>

    <span class="ActionScriptReserved">public</span> <span class="ActionScriptclass">class</span> <span class="ActionScriptDefault_Text">AuxFunctions</span> <span class="ActionScriptBracket/Brace">{</span>

        <span class="ActionScriptASDoc">/**
         * Gets the R (xx0000) bits from a number
         *
         * @param        p_num                Number        Color number (ie, 0xffff00)
         * @return                            Number        The R value
         */</span>
        <span class="ActionScriptReserved">public</span> <span class="ActionScriptReserved">static</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">numberToR</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">p_num</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptBracket/Brace">{</span>
            <span class="ActionScriptComment">// The initial &amp; is meant to crop numbers bigger than 0xffffff
</span>            <span class="ActionScriptReserved">return</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">p_num</span> <span class="ActionScriptOperator">&amp;</span> 0<span class="ActionScriptDefault_Text">xff0000</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptOperator">&gt;&gt;</span> 16;
        <span class="ActionScriptBracket/Brace">}</span>

        <span class="ActionScriptASDoc">/**
         * Gets the G (00xx00) bits from a number
         *
         * @param        p_num                Number        Color number (ie, 0xffff00)
         * @return                            Number        The G value
         */</span>
        <span class="ActionScriptReserved">public</span> <span class="ActionScriptReserved">static</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">numberToG</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">p_num</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptBracket/Brace">{</span>
            <span class="ActionScriptReserved">return</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">p_num</span> <span class="ActionScriptOperator">&amp;</span> 0<span class="ActionScriptDefault_Text">xff00</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptOperator">&gt;&gt;</span> 8;
        <span class="ActionScriptBracket/Brace">}</span>

        <span class="ActionScriptASDoc">/**
         * Gets the B (0000xx) bits from a number
         *
         * @param        p_num                Number        Color number (ie, 0xffff00)
         * @return                            Number        The B value
         */</span>
        <span class="ActionScriptReserved">public</span> <span class="ActionScriptReserved">static</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">numberToB</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">p_num</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptBracket/Brace">{</span>
            <span class="ActionScriptReserved">return</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">p_num</span> <span class="ActionScriptOperator">&amp;</span> 0<span class="ActionScriptDefault_Text">xff</span><span class="ActionScriptBracket/Brace">)</span>;
        <span class="ActionScriptBracket/Brace">}</span>

        <span class="ActionScriptASDoc">/**
         * Checks whether a string is on an array
         *
         * @param        p_string            String        String to search for
         * @param        p_array                Array        Array to be searched
         * @return                            Boolean        Whether the array contains the string or not
         */</span>
        <span class="ActionScriptReserved">public</span> <span class="ActionScriptReserved">static</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">isInArray</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">p_string</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">String</span>, <span class="ActionScriptDefault_Text">p_array</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Array</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Boolean</span> <span class="ActionScriptBracket/Brace">{</span>
            <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">l</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">uint</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">p_array</span>.<span class="ActionScriptDefault_Text">length</span>;
            <span class="ActionScriptReserved">for</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">i</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">uint</span> <span class="ActionScriptOperator">=</span> 0; <span class="ActionScriptDefault_Text">i</span> <span class="ActionScriptOperator">&lt;</span> <span class="ActionScriptDefault_Text">l</span>; <span class="ActionScriptDefault_Text">i</span><span class="ActionScriptOperator">++</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
                <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">p_array</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">i</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">==</span> <span class="ActionScriptDefault_Text">p_string</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptReserved">return</span> <span class="ActionScriptReserved">true</span>;
            <span class="ActionScriptBracket/Brace">}</span>
            <span class="ActionScriptReserved">return</span> <span class="ActionScriptReserved">false</span>;
        <span class="ActionScriptBracket/Brace">}</span>

        <span class="ActionScriptASDoc">/**
         * Returns the number of properties an object has
         *
         * @param        p_object            Object        Target object with a number of properties
         * @return                            Number        Number of total properties the object has
         */</span>
        <span class="ActionScriptReserved">public</span> <span class="ActionScriptReserved">static</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">getObjectLength</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">p_object</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Object</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">uint</span> <span class="ActionScriptBracket/Brace">{</span>
            <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">totalProperties</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">uint</span> <span class="ActionScriptOperator">=</span> 0;
            <span class="ActionScriptReserved">for</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">pName</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">String</span> <span class="ActionScriptReserved">in</span> <span class="ActionScriptDefault_Text">p_object</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptDefault_Text">totalProperties</span> <span class="ActionScriptOperator">++</span>;
            <span class="ActionScriptReserved">return</span> <span class="ActionScriptDefault_Text">totalProperties</span>;
        <span class="ActionScriptBracket/Brace">}</span>
        
        <span class="ActionScriptComment">/* Takes a variable number of objects as parameters and &quot;adds&quot; their properties, form left to right. If a latter object defines a property as null, it will be removed from the final object
        * @param        args                Object(s)    A variable number of objects
        * @return                            Object        An object with the sum of all paremeters added as properties.
        */</span>
        <span class="ActionScriptReserved">public</span> <span class="ActionScriptReserved">static</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">concatObjects</span><span class="ActionScriptBracket/Brace">(</span>...<span class="ActionScriptDefault_Text">args</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptOperator">:</span> <span class="ActionScriptDefault_Text">Object</span><span class="ActionScriptBracket/Brace">{</span>
            <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">finalObject</span> <span class="ActionScriptOperator">:</span> <span class="ActionScriptDefault_Text">Object</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptBracket/Brace">{}</span>;
            <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">currentObject</span> <span class="ActionScriptOperator">:</span> <span class="ActionScriptDefault_Text">Object</span>;
            <span class="ActionScriptReserved">for</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">i</span> <span class="ActionScriptOperator">:</span> <span class="ActionScriptDefault_Text">int</span> <span class="ActionScriptOperator">=</span> 0; <span class="ActionScriptDefault_Text">i</span> <span class="ActionScriptOperator">&lt;</span> <span class="ActionScriptDefault_Text">args</span>.<span class="ActionScriptDefault_Text">length</span>; <span class="ActionScriptDefault_Text">i</span><span class="ActionScriptOperator">++</span><span class="ActionScriptBracket/Brace">){</span>
                <span class="ActionScriptDefault_Text">currentObject</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">args</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">i</span><span class="ActionScriptBracket/Brace">]</span>;
                <span class="ActionScriptReserved">for</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">prop</span> <span class="ActionScriptOperator">:</span> <span class="ActionScriptDefault_Text">String</span> <span class="ActionScriptReserved">in</span> <span class="ActionScriptDefault_Text">currentObject</span><span class="ActionScriptBracket/Brace">){</span>
                    <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">currentObject</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">prop</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">==</span> <span class="ActionScriptReserved">null</span><span class="ActionScriptBracket/Brace">){</span>
                        <span class="ActionScriptComment">// delete in case is null
</span>                        <span class="ActionScriptReserved">delete</span> <span class="ActionScriptDefault_Text">finalObject</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">prop</span><span class="ActionScriptBracket/Brace">]</span>;
                    <span class="ActionScriptBracket/Brace">}</span><span class="ActionScriptReserved">else</span><span class="ActionScriptBracket/Brace">{</span>
                        <span class="ActionScriptDefault_Text">finalObject</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">prop</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">currentObject</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">prop</span><span class="ActionScriptBracket/Brace">]</span>
                    <span class="ActionScriptBracket/Brace">}</span>
                <span class="ActionScriptBracket/Brace">}</span>
            <span class="ActionScriptBracket/Brace">}</span>
            <span class="ActionScriptReserved">return</span> <span class="ActionScriptDefault_Text">finalObject</span>;
        <span class="ActionScriptBracket/Brace">}</span>
    <span class="ActionScriptBracket/Brace">}</span>
<span class="ActionScriptBracket/Brace">}</span></pre></body>
</html>
